package cn.edu.scau.cmi.chenzehan.client;
import cn.edu.scau.cmi.chenzehan.singleFactoryPattern.factory.claims_Factory;
import cn.edu.scau.cmi.chenzehan.singleFactoryPattern.insurance.Insurance_claims;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

public class SinpleFactory extends Application {

	@Override
	public void start(Stage primaryStage) throws Exception {

		Parent root = FXMLLoader.load(getClass().getResource("factory.fxml"));
		Button button = (Button)root.lookup("#button1");
		ChoiceBox<String> choiceBox = (ChoiceBox)root.lookup("#choiceBox1");
		TextArea textField = (TextArea)root.lookup("#textfield1");
		
		choiceBox.setItems(FXCollections.observableArrayList(
			    "驾驶员身体受伤", "汽车损坏", 
			    "人员伤亡"));
		
		button.setOnAction(e->{
			if(choiceBox.getValue() == null) {
				textField.appendText("请选择上述保险中的一种"+"\n");
			}
			else
			{
				Insurance_claims in = claims_Factory.instance(choiceBox.getValue());
				textField.appendText(in.getInfo()+"\n");
			}
				
			
		});
        Scene scene = new Scene(root);
        
		primaryStage.setTitle("实验二:简单工厂方法");
	    primaryStage.setScene(scene);
		primaryStage.show();
	}
	public static void main(String[] args) {
		Application.launch(args);
	}

}
